package com.atguigu.yygh.user.service.impl;

import com.atguigu.yygh.DictFeignClient;
import com.atguigu.yygh.enums.DictEnum;
import com.atguigu.yygh.model.user.Patient;
import com.atguigu.yygh.user.mapper.PatientMapper;
import com.atguigu.yygh.user.service.PatientService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PatientServiceImpl extends
        ServiceImpl<PatientMapper, Patient> implements PatientService {
    @Autowired
    private DictFeignClient dictFeignClient;
    //获取就诊人列表
    @Override
    public List<Patient> findAllUserId(Long userId) {
        QueryWrapper<Patient> wrapper=new QueryWrapper<Patient>();
        wrapper.eq("user_id",userId);
        List<Patient> patients= baseMapper.selectList(wrapper);
        patients.stream().forEach((patient)->{
            this.packPatient(patient);
        });
        return patients;
    }
    @Override
    public Patient getPatientId(Long id) {
        return this.packPatient(baseMapper.selectById(id));
    }
    //Patient对象里面其他参数封装
    private Patient packPatient(Patient patient) {
        System.out.println("ok");
        String certificatesTypeString =
           dictFeignClient.getNameByValueAndDicCode("1","ROOT");//联系人证件
        String certificatesNo = patient.getCertificatesNo();
        String certificatesType = patient.getCertificatesType();
        //根据证件类型编码，获取证件类型具体指
        String certificatesTypeString1 =
                dictFeignClient.getNameByString10(patient.getCertificatesType());//联系人证件
        patient.getParam().put("certificatesTypeString", certificatesTypeString1);
        //联系人证件类型
        if(StringUtils.isNotEmpty(patient.getContactsCertificatesType())){
            String contactsCertificatesTypeString =
            dictFeignClient.getNameByString10(patient.getContactsCertificatesType());
            patient.getParam().put("contactsCertificatesTypeString", contactsCertificatesTypeString);
        }

        //省
        if(StringUtils.isNotEmpty(patient.getProvinceCode())){
            String provinceString = dictFeignClient.getNameByvalue(Integer.parseInt(patient.getProvinceCode()));
            patient.getParam().put("provinceString", provinceString);
        }

        //市
        if(StringUtils.isNotEmpty(patient.getCityCode())){
            String cityString = dictFeignClient.getNameByvalue(Integer.parseInt(patient.getCityCode()));
            patient.getParam().put("cityString", cityString);
        }


        //区
        if(StringUtils.isNotEmpty(patient.getDistrictCode())){
            String districtString = dictFeignClient.getNameByvalue(Integer.parseInt(patient.getDistrictCode()));
            patient.getParam().put("districtString", districtString);
        }
//
//


        if(  StringUtils.isNotEmpty(patient.getProvinceCode()) && StringUtils.isNotEmpty(patient.getCityCode()) && StringUtils.isNotEmpty(patient.getDistrictCode()))

        patient.getParam().put("fullAddress", patient.getProvinceCode() + patient.getCityCode() + patient.getDistrictCode() + patient.getAddress());

        return patient;


    }
}